package cn.com.nou.base.service.account;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.nou.base.dao.NouUserInfoMapper;
import cn.com.nou.base.dao.organizationmgt.CollageInfoMapper;
import cn.com.nou.common.NouException;
import cn.com.nou.common.entity.NouAccountInfo;
import cn.com.nou.common.entity.NouCollageInfoT;
import cn.com.nou.common.entity.NouUserInfoT;
import cn.com.nou.common.utils.EncryptionUtils;

/**
 * 
 * @ClassName: AccountManageServiceImpl
 * @Description: 管理端-账号管理
 */
@Service
public class AccountManageServiceImpl implements AccountManageService {
	private static final Logger logger = LoggerFactory.getLogger(AccountManageServiceImpl.class);

	@Autowired
	private NouUserInfoMapper userInfoMapper;
	@Autowired
	private CollageInfoMapper collageInfoMapper;

	@Override
	public NouAccountInfo getAccount(String userId) {
		NouAccountInfo nouAccountInfo = new NouAccountInfo();
		NouUserInfoT nouUserInfoT = userInfoMapper.getUser(userId);
		if (nouUserInfoT != null) {
			// 设置账号信息
			nouAccountInfo.setNouUserInfoT(nouUserInfoT);

			// 设置学校信息
			NouCollageInfoT nouCollageInfoT = collageInfoMapper.getCollageById(nouUserInfoT.getSchoolId());
			if (nouCollageInfoT != null) {
				nouAccountInfo.setNouCollageInfoT(nouCollageInfoT);
			}

		}
		return nouAccountInfo;
	}

//	@Override
//	public void updAccount(NouUserInfoT nouUserInfoT) {
//		NouUserInfoT userInfo = userInfoMapper.getUser(nouUserInfoT.getUserId());
//		if (userInfo == null) {
//			logger.warn("该账户不存在");
//			throw new NouException("该账户不存在");
//		}
//		// 修改密码
//		if (StringUtils.isNotEmpty(nouUserInfoT.getPassWord())) {
//			if (!EncryptionUtils.encryptPassword(nouUserInfoT.getOldPassword()).equals(userInfo.getPassWord())) {
//				logger.warn("原密码错误，修改失败");
//				throw new NouException("原密码错误，修改失败");
//			}
//			userInfo.setPassWord(EncryptionUtils.encryptPassword(nouUserInfoT.getPassWord()));
//		// 修改个人信息	
//		} else {
//			userInfo.setAvatar(nouUserInfoT.getAvatar());
//			userInfo.setContractPhone(nouUserInfoT.getContractPhone());
//			userInfo.setEmail(nouUserInfoT.getEmail());
//			userInfo.setAddress(nouUserInfoT.getAddress());
//			userInfo.setNote(nouUserInfoT.getNote());
//		}
//		userInfoMapper.updAccount(userInfo);
//
//	}

}
